/**
 *	@file	field_pictview.c
 *	@brief	フィールド　写真Viewerメニュー
 *	@author	Miyuki Iwasawa
 *	@date	08.06.02
 */
#include "common.h"

#include "gflib/strbuf_family.h"
#include "gflib/touchpanel.h"

#include "system/pm_overlay.h"
#include "system/lib_pack.h"
#include "system/arc_tool.h"
#include "system/arc_util.h"
#include "system/pm_overlay.h"

#include "system/clact_util.h"
#include "system/render_oam.h"
#include "system/pm_str.h"

#include "system/bmp_menu.h"
#include "system/window.h"
#include "system/fontproc.h"
#include "system/pms_word.h"
#include "system/wordset.h"
#include "system/msgdata.h"
#include "system/msgdata_util.h"

#include "fld_bmp.h"
#include "fieldmap.h"
#include "fieldsys.h"
#include "talk_msg.h"
#include "fieldsys.h"
#include "field_subscreen.h"
#include "field_sublcd_menu.h"
#include "field_clact.h"

#include "system/snd_play.h"
#include "system/snd_tool.h"
#include "data/clact_util/clact_header.naix"
#include "msgdata/msg.naix"
#include "msgdata/msg_album.h"

#include "savedata/picture_util.h"
#include "field_pictview.h"
#include "field_picture.h"
#include "application/album/album_gra.naix"

#define DFRM_MSG	(GF_BGL_FRAME1_S)
#define DFRM_BACK	(GF_BGL_FRAME2_S)
#define DFRM_THUMB	(GF_BGL_FRAME3_S)

#define DFRM_MSG_PRI	(0)
#define DFRM_BACK_PRI	(3)
#define DFRM_THUMB_PRI	(2)

#define PIC_BG_SCRL_X	(-4)

#define WORDSET_PICTVIEW_BUFLEN	(16)
#define WORDSET_PICTVIEW_BUFNUM	(6)
#define PICTVIEW_MSG_BUFLEN		(128)	///<メッセージ展開バッファ長

#define MIDX_PIC_MAX	(2)

///////////////////////////////////////////
///パレット定義
#define BACK_FONT_PAL	(1)
#define MSG_FONT_PAL	(10)

#define	FCOL_N_BLACK	( GF_PRINTCOLOR_MAKE( 3, 2, FBMP_COL_NULL ) )		// フォントカラー：黒

//////////////////////////////////////////////////////
//BMPウィンドウ領域定義

///やめるボタン
#define	BMP_BACK_PX	( 25 )
#define	BMP_BACK_PY	( 21 )
#define	BMP_BACK_SX	( 6 )
#define	BMP_BACK_SY	( 2 )
#define BMP_BACK_FRM	( DFRM_MSG )
#define	BMP_BACK_PAL	( BACK_FONT_PAL )
#define BMP_BACK_CGX_SIZ	(BMP_BACK_SX*BMP_BACK_SY)
#define	BMP_BACK_CGX	( 512-BMP_BACK_CGX_SIZ )

#define	BMP_PIC_PX	( 1 )
#define	BMP_PIC_PY	( 8 )
#define	BMP_PIC_SX	( 28 )
#define	BMP_PIC_SY	( 8 )
#define BMP_PIC_FRM	( DFRM_MSG )
#define	BMP_PIC_PAL	( MSG_FONT_PAL )
#define BMP_PIC_CGX_SIZ	(BMP_PIC_SX*BMP_PIC_SY)
#define	BMP_PIC_CGX	( BMP_BACK_CGX-BMP_PIC_CGX_SIZ )

/////////////////////////////////////////////////
#define THUMB_BG_W	(5)
#define THUMB_BG_H	(5)

#define THUMB_BG_PX	(13)
#define THUMB_BG_PY	(2)

#define THUMB_CGX_SIZ		(THUMB_BG_W*THUMB_BG_H)
#define THUMB_CGXSRC_OFFSET	(64)

/////////////////////////////////////////////////////
#define ACT_RET_PX	(28*8)
#define ACT_RET_PY	(22*8)
#define ACT_ALLOW_PY	(5*8)
#define ACT_ALLOWL_PX	(11*8)
#define ACT_ALLOWR_PX	(21*8)

#define TP_RET_PX		(24*8+2)
#define TP_RET_PY		(20*8+2)
#define TP_RET_W		(64-4)
#define TP_RET_H		(32-6)

#define TP_PAGEU_PX		(ACT_ALLOWL_PX-8)
#define TP_PAGED_PX		(ACT_ALLOWR_PX-8)
#define TP_PAGE_PY		(ACT_ALLOW_PY-16)
#define TP_PAGE_W		(16)
#define TP_PAGE_H		(32)

//////////////////////////////////////////////////////////
//
enum{
 ACT_BACK,
 ACT_ALLOW_L,
 ACT_ALLOW_R,
 ACT_MAX,
};

enum{
 ANM_AL_LN,
 ANM_AL_LT,
 ANM_AL_LF,
 ANM_AL_RN,
 ANM_AL_RT,
 ANM_AL_RF,
 ANM_CURSOR,
 ANM_CUR_S,
 ANM_RET,
 ANM_RETA,
};

enum{
 WIN_BACK,
 WIN_PIC,
 WIN_MAX,
};

typedef struct _PICTVIEW_MSG{
	MSGDATA_MANAGER*	man;

	WORDSET* wset;		///<ワーク

	STRBUF	*tmp;
	STRBUF	*back;
	STRBUF	*pic[MIDX_PIC_MAX];
}PICTVIEW_MSG;

typedef struct _FPV_WORK{
	int				heapID;
	int				seq;
	int				key_mode;
	PICTVIEWER_REQ	ret_code;

	SAVEDATA*		save;
	FIELDSYS_WORK	*fsys;
	GF_BGL_INI		*bgl;
	FLD_ALBUM_EVENT* fae;

	TCB_PTR			tcb;

	PICTVIEW_MSG	msg;
	GF_BGL_BMPWIN	win[WIN_MAX];

	FIELD_CLACT	fcat;
	CLACT_WORK_PTR	act[ACT_MAX];
	u8				act_anim_id;

	SUBLCD_PICTDATA	pic_data;
}FPV_WORK;



//////////////////////////////////////////////////////////////
//データ配列
///TCATS_RES_ARC
static const TCATS_RESOURCE_FILE_LIST album_actres_list = {
	NARC_clact_header_album_chr_resdat,		// キャラクタ
	NARC_clact_header_album_pal_resdat,		// パレット
	NARC_clact_header_album_cell_resdat,		// セル
	NARC_clact_header_album_canm_resdat,		// セルアニメ
	TCATS_RESID_NULL,							// マルチセル
	TCATS_RESID_NULL,							// マルチセルアニメ
	NARC_clact_header_album_celact_cldat		// ヘッダー
};

//////////////////////////////////////////////////////////////////////
//プロトタイプ
static void tcb_FieldPictViewer(TCB_PTR tcb,void* p_work);

static void sub_ResInit(FPV_WORK* wk);
static void sub_ResRelease(FPV_WORK* wk);
static int sub_Input(FPV_WORK* wk);
static int sub_InputKey(FPV_WORK* wk);
static int sub_InputTouch(FPV_WORK* wk);

static void sub_BGLInit(FPV_WORK* wk);
static void sub_BGLRelease(FPV_WORK* wk);
static void sub_2DResInit(FPV_WORK* wk);
static void sub_2DResRelease(FPV_WORK* wk);
static void sub_MsgDataInit(FPV_WORK* wk);
static void sub_MsgDataRelease(FPV_WORK* wk);
static void sub_BmpWinAdd(FPV_WORK* wk);
static void sub_BmpWinDel(FPV_WORK* wk);
static void sub_ActorInit(FPV_WORK* wk);
static void sub_ActorRelease(FPV_WORK* wk);
static void sub_ActAnimSet(FPV_WORK* wk,u8 act_id);
static int sub_ActAnimWait(FPV_WORK* wk);

static void sub_ThumbnailWrite(FPV_WORK* wk);
static void sub_PictMsgExpand(PICTURE_DATA* pic,WORDSET* wset,STRBUF* tmp,int heapID, SAVEDATA *save);
static void sub_PictDataDraw(FPV_WORK* wk);

static u8 GetPicMonsNum(const PICTURE_DATA* pic);







////////////////////////////////////////////////////////////////////////////////////////



/**
 *	@brief	写真Viewer下画面制御タスク初期化
 */
TCB_PTR	FieldPictViewer_Init(FIELDSYS_WORK* fsys)
{
	FPV_WORK* wk;
	TCB_PTR	tcb;

	wk = sys_AllocMemory(HEAPID_WORLD,sizeof(FPV_WORK));
	MI_CpuClear8(wk,sizeof(FPV_WORK));

	wk->heapID = HEAPID_WORLD;
	wk->fsys = fsys;
	wk->bgl = fsys->bgl;
	wk->save = fsys->savedata;
	wk->fae = (FLD_ALBUM_EVENT*)fsys->sublcd_wk;
	wk->key_mode = KeyTouchStatus_CheckTouchOrKey(&fsys->KeyTouchStatus);

	FieldAlbumEvent_GetPictureData(wk->fae,&wk->pic_data);

	//タスクを追加
	tcb = TCB_Add(tcb_FieldPictViewer, wk, 1);

	return tcb;
}

/**
 *	@brief	写真Viewer下画面制御タスク削除
 */
void FieldPictViewer_End(FIELDSYS_WORK* fsys)
{
	FPV_WORK* wk;

	wk = (FPV_WORK*)TCB_GetWork(fsys->sublcd_controler);

	//キーモード書き戻し
	KeyTouchStatus_SetTouchOrKey(&fsys->KeyTouchStatus,wk->key_mode);

	sub_ResRelease(wk);

	sys_FreeMemoryEz(wk);
	TCB_Delete(fsys->sublcd_controler);
	fsys->sublcd_controler = NULL;
}

/**
 *	@brief	写真Viewer下画面タスク
 */
static void tcb_FieldPictViewer(TCB_PTR tcb,void* p_work)
{
	FPV_WORK* wk = (FPV_WORK*)p_work;

	switch(wk->seq){
	case 0:
		sub_ResInit(wk);
		wk->seq++;
		return;
	case 1:
		//切り替え完了時を取得したいが、無理っぽいので、
		//fadeがおわるまで操作不可能にする
		//BTS4808 nagihashi
		if( GX_GetMasterBrightness() != 0 ){
			break;
		}

		if(sub_Input(wk)){
			wk->seq++;
		}
		break;
	case 2:
		if(!sub_ActAnimWait(wk)){
			break;
		}
		FieldAlbumEvent_PictViewerMainControlReq(wk->fae,wk->ret_code);
		break;
	}
	CLACT_Draw( wk->fcat.cas );
	return;
}

/*
 *	@brief	リソース初期化
 */
static void sub_ResInit(FPV_WORK* wk)
{
	sub_BGLInit(wk);
	sub_2DResInit(wk);
	sub_MsgDataInit(wk);

	sub_BmpWinAdd(wk);
	sub_ActorInit(wk);
	sub_PictDataDraw(wk);
}

/*
 *	@brief	リソース解放
 */
static void sub_ResRelease(FPV_WORK* wk)
{
	sub_ActorRelease(wk);
	sub_BmpWinDel(wk);
	sub_MsgDataRelease(wk);
	sub_2DResRelease(wk);
	sub_BGLRelease(wk);
}

/*
 *	@brief	入力取得
 */
static int sub_Input(FPV_WORK* wk)
{
	int ret;

	ret = sub_InputTouch(wk);
	if(!ret){
		ret = sub_InputKey(wk);
		if(!ret){
			wk->key_mode = APP_KTST_KEY;
		}
	}else{
		wk->key_mode = APP_KTST_TOUCH;
	}

	switch(ret){
	case 1:
		sub_ActAnimSet(wk,ACT_BACK);
		Snd_SePlay(SEQ_SE_DP_DECIDE);
		wk->ret_code = PICTVIEWER_REQ_BACK;
		break;
	case 2:
		if(wk->pic_data.pic_idx == 0){
			return 0;
		}
		sub_ActAnimSet(wk,ACT_ALLOW_L);
		Snd_SePlay(SEQ_SE_DP_SELECT);
		wk->ret_code = PICTVIEWER_REQ_PREV;
		break;
	case 3:
		if(wk->pic_data.pic_idx >= (wk->pic_data.pic_max-1)){
			return 0;
		}
		sub_ActAnimSet(wk,ACT_ALLOW_R);
		Snd_SePlay(SEQ_SE_DP_SELECT);
		wk->ret_code = PICTVIEWER_REQ_NEXT;
		break;
	default:
		return 0;
	}
	return ret;
}

/**
 *	@brief	キー入力取得
 */
static int sub_InputKey(FPV_WORK* wk)
{
	if(sys.trg & (PAD_BUTTON_DECIDE|PAD_BUTTON_CANCEL)){
		return 1;
	}
	if(sys.trg & PAD_KEY_LEFT){
		return 2;
	}
	if(sys.trg & PAD_KEY_RIGHT){
		return 3;
	}
	return 0;
}

/**
 *	@brief	タッチ入力取得
 */
static int sub_InputTouch(FPV_WORK* wk)
{
	int ret;

	///タッチパネル制御テーブル
	static const RECT_HIT_TBL TpRect[] = {
	//	{0,191,0,255}, ty,by,lx,rx
		{TP_RET_PY,TP_RET_PY+TP_RET_H,TP_RET_PX,TP_RET_PX+TP_RET_W},
		{TP_PAGE_PY,TP_PAGE_PY+TP_PAGE_H,TP_PAGEU_PX,TP_PAGEU_PX+TP_PAGE_W},
		{TP_PAGE_PY,TP_PAGE_PY+TP_PAGE_H,TP_PAGED_PX,TP_PAGED_PX+TP_PAGE_W},
		{RECT_HIT_END,0,0,0}
	};
	ret = GF_TP_RectHitTrg(TpRect);
	if(	ret == RECT_HIT_NONE){
		return 0;
	}
	return ret+1;
}

/*
 *	@brief	BGL初期化
 */
static void sub_BGLInit(FPV_WORK* wk)
{
	//BG3は256色
	GXS_SetGraphicsMode( GX_BGMODE_3 );

	{	// 下画面　テキスト面
		GF_BGL_BGCNT_HEADER TextBgCntDat = {
			0, 0, 0x800, 0, GF_BGL_SCRSIZ_256x256, GX_BG_COLORMODE_16,
			GX_BG_SCRBASE_0x7800, GX_BG_CHARBASE_0x00000, GX_BG_EXTPLTT_01,
			DFRM_MSG_PRI, 0, 0, FALSE
		};
		GF_BGL_BGControlSet( wk->bgl, DFRM_MSG, &TextBgCntDat, GF_BGL_MODE_TEXT );
		GF_BGL_ScrClear( wk->bgl, DFRM_MSG );
	}

	{	// 下画面　背景
		GF_BGL_BGCNT_HEADER TextBgCntDat = {
			0, 0, 0x800, 0, GF_BGL_SCRSIZ_256x256, GX_BG_COLORMODE_16,
			GX_BG_SCRBASE_0x7000, GX_BG_CHARBASE_0x00000, GX_BG_EXTPLTT_01,
			DFRM_BACK_PRI, 0, 0, FALSE
		};
		GF_BGL_BGControlSet( wk->bgl, DFRM_BACK, &TextBgCntDat, GF_BGL_MODE_TEXT );
		GF_BGL_ScrClear( wk->bgl, DFRM_BACK );
	}

	{	// 下画面　背景サムネイル
		GF_BGL_BGCNT_HEADER TextBgCntDat = {
			0, 0, 0x800, 0, GF_BGL_SCRSIZ_256x256, GX_BG_COLORMODE_256,
			GX_BG_SCRBASE_0x6800, GX_BG_CHARBASE_0x04000, GX_BG_EXTPLTT_01,
			DFRM_THUMB_PRI, 0, 0, FALSE
		};
		GF_BGL_BGControlSet( wk->bgl, DFRM_THUMB, &TextBgCntDat, GF_BGL_MODE_256X16 );
		GF_BGL_ScrClear( wk->bgl, DFRM_THUMB );
	}

	GF_BGL_ClearCharSet( DFRM_MSG, 32, 0, wk->heapID );
	GF_BGL_ClearCharSet( DFRM_THUMB, 64, 0, wk->heapID );

	//下画面サムネール面スクロールセット
	GF_BGL_ScrollSet(wk->bgl,DFRM_THUMB,GF_BGL_SCROLL_X_SET,PIC_BG_SCRL_X);
}

/**
 * @brief	BGL解放
 */
static void sub_BGLRelease(FPV_WORK* wk)
{
	//上画面サムネール面スクロールリセット
	GF_BGL_ScrollSet(wk->bgl,DFRM_THUMB,GF_BGL_SCROLL_X_SET,0);

	GF_BGL_BGControlExit(wk->bgl, DFRM_THUMB );
	GF_BGL_BGControlExit(wk->bgl, DFRM_BACK );
	GF_BGL_BGControlExit(wk->bgl, DFRM_MSG );

	GXS_SetGraphicsMode( GX_BGMODE_0 );
}

/**
 * @brief	2Dリソース初期化
 */
static void sub_2DResInit(FPV_WORK* wk)
{
	ARCHANDLE* handle;
	NNSG2dCharacterData* pChar;
	void*	pCharBuf;
	u32 ofs;

	//アーカイブのハンドルを取得
	handle = ArchiveDataHandleOpen(ARC_ALBUM_GRA,wk->heapID);

	// 下画面ＢＧパレット転送
	ArcUtil_HDL_PalSet( handle,
		NARC_album_gra_bg_nclr,PALTYPE_SUB_BG,  0, 0, wk->heapID );

	//サブ下画面背景転送
	ArcUtil_HDL_BgCharSet( handle,
		NARC_album_gra_bgs_back_ncgr, wk->bgl, DFRM_BACK, 0, 0, FALSE, wk->heapID);
	ArcUtil_HDL_ScrnSet( handle,
		NARC_album_gra_bgs_back_nscr, wk->bgl, DFRM_BACK, 0, 0, FALSE, wk->heapID);

	//サムネールリソース転送
	pCharBuf = ArcUtil_HDL_CharDataGet( handle,
		NARC_album_gra_bgd_back_ncgr,FALSE, &pChar, wk->heapID);

	{
		u8 thumb = (wk->pic_data.pic->thumbnail+1);
		ofs = ((THUMB_CGX_SIZ*thumb)+THUMB_CGXSRC_OFFSET)*64;
		GF_BGL_LoadCharacter(wk->bgl, DFRM_THUMB,
			&((u8*)(pChar->pRawData))[ofs],THUMB_CGX_SIZ*64, 1);
	}
	sys_FreeMemoryEz(pCharBuf);
	//ハンドル解放
	ArchiveDataHandleClose( handle );
}

/**
 * @brief	2Dリソース解放
 */
static void sub_2DResRelease(FPV_WORK* wk)
{
	return;
}

/**
 *	@brief	メッセージデータ初期化
 */
static void sub_MsgDataInit(FPV_WORK* wk)
{
	int i;

	//タッチフォントロード
	FontProc_LoadFont(FONT_TOUCH,wk->heapID);

	wk->msg.man = MSGMAN_Create(MSGMAN_TYPE_NORMAL,ARC_MSG,
			NARC_msg_album_dat,wk->heapID);

	wk->msg.wset = WORDSET_CreateEx(WORDSET_PICTVIEW_BUFNUM,WORDSET_PICTVIEW_BUFLEN,wk->heapID);
	wk->msg.tmp = STRBUF_Create(PICTVIEW_MSG_BUFLEN,wk->heapID);

	wk->msg.back = MSGMAN_AllocString(wk->msg.man,msg_panel_back);

	for(i = 0;i < MIDX_PIC_MAX;i++){
		wk->msg.pic[i] = MSGMAN_AllocString(wk->msg.man,msg_pic_exp01+i);
	}
}

/**
 *	@brief	メッセージデータ解放
 */
static void sub_MsgDataRelease(FPV_WORK* wk)
{
	int i;

	//文字列バッファ削除
	for(i = 0;i < MIDX_PIC_MAX;i++){
		STRBUF_Delete(wk->msg.pic[i]);
	}
	STRBUF_Delete(wk->msg.back);
	STRBUF_Delete(wk->msg.tmp);
	WORDSET_Delete(wk->msg.wset);

	MSGMAN_Delete(wk->msg.man);

	//タッチフォントアンロード
	FontProc_UnloadFont(FONT_TOUCH);
}
/**
 *	@brief	BMPウィンドウ初期化
 */
static void sub_BmpWinAdd(FPV_WORK* wk)
{
	int i;
	static const BMPWIN_DAT BmpWinData[] = {
	 {	// 「もどるボタン」
		BMP_BACK_FRM, BMP_BACK_PX, BMP_BACK_PY,
		BMP_BACK_SX, BMP_BACK_SY, BMP_BACK_PAL, BMP_BACK_CGX
	 },
	 {	// 「写真情報」
		BMP_PIC_FRM, BMP_PIC_PX, BMP_PIC_PY,
		BMP_PIC_SX, BMP_PIC_SY, BMP_PIC_PAL, BMP_PIC_CGX
	 },
	};

	for( i=0; i<WIN_MAX; i++ ){
		GF_BGL_BmpWinAddEx( wk->bgl, &wk->win[i], &BmpWinData[i] );
		GF_BGL_BmpWinDataFill( &wk->win[i], 0 );
	}
}

/**
 *	@brief	BMPウィンドウ解放
 */
static void sub_BmpWinDel(FPV_WORK* wk)
{
	int i;
	for( i=0; i<WIN_MAX; i++ ){
		GF_BGL_BmpWinOff( &wk->win[i] );
		GF_BGL_BmpWinDel( &wk->win[i] );
	}
}

/**
 *	@brief	アクター初期化
 */
static void sub_ActorInit(FPV_WORK* wk)
{
	int i;

	static const TCATS_OBJECT_ADD_PARAM	ActAddParam[] =
	{
		{	// 戻るボタン
			1,	//ID
			ACT_RET_PX, ACT_RET_PY, 0,	//x,y,z
			ANM_RET, 0xFF, 0, NNS_G2D_VRAM_TYPE_2DSUB,	//anmNO,pri,pal,d_area
			TCATS_PALMODE_AUTO, 0, 0, 0	//prm1,prm2,prm3,prm4
		},
		{	// ←
			1,	//ID
			ACT_ALLOWL_PX, ACT_ALLOW_PY, 0,	//x,y,z
			ANM_AL_LN, 2, 0, NNS_G2D_VRAM_TYPE_2DSUB,	//anmNO,pri,pal,d_area
			TCATS_PALMODE_AUTO, 0, 0, 0	//prm1,prm2,prm3,prm4
		},
		{	// →
			1,	//ID
			ACT_ALLOWR_PX, ACT_ALLOW_PY, 0,	//x,y,z
			ANM_AL_RN, 2, 0, NNS_G2D_VRAM_TYPE_2DSUB,	//anmNO,pri,pal,d_area
			TCATS_PALMODE_AUTO, 0, 0, 0	//prm1,prm2,prm3,prm4
		},
	};

	FieldCellActSet( &wk->fcat, &album_actres_list, ACT_MAX, wk->heapID);

	for( i=0; i< ACT_MAX; i++ ){
		wk->act[i] = FieldCellActAdd( &wk->fcat, &ActAddParam[i] );
		CLACT_SetDrawFlag( wk->act[i], TRUE);
		CLACT_SetAnmFlag( wk->act[i], TRUE);
	}

	//ページカーソルの状態セット
	if(wk->pic_data.pic_idx == 0){
		CLACT_AnmChg(wk->act[ACT_ALLOW_L],ANM_AL_LF);
	}else{
		CLACT_AnmChg(wk->act[ACT_ALLOW_L],ANM_AL_LN);
	}
	if(wk->pic_data.pic_idx >= (wk->pic_data.pic_max-1)){
		CLACT_AnmChg(wk->act[ACT_ALLOW_R],ANM_AL_RF);
	}else{
		CLACT_AnmChg(wk->act[ACT_ALLOW_R],ANM_AL_RN);
	}

	GF_Disp_GXS_VisibleControl( GX_PLANEMASK_OBJ, VISIBLE_ON );
}

/**
 *	@brief	アクター解放
 */
static void sub_ActorRelease(FPV_WORK* wk)
{
	int i;

	for( i=0; i < ACT_MAX; i++ ){
		CLACT_Delete( wk->act[i] );
	}
	FieldCellActDelete( &wk->fcat );

	GF_Disp_GXS_VisibleControl( GX_PLANEMASK_OBJ, VISIBLE_OFF );
}

/**
 *	@brief	アクターアニメセット
 */
static void sub_ActAnimSet(FPV_WORK* wk,u8 act_id)
{
	static const u8 pat[] = {ANM_RETA,ANM_AL_LT,ANM_AL_RT};
	wk->act_anim_id = act_id;

	CLACT_AnmChg(wk->act[act_id],pat[act_id]);
	CLACT_AnmReStart(wk->act[act_id]);
}

/**
 *	@brief	アクターアニメ待ち
 */
static int sub_ActAnimWait(FPV_WORK* wk)
{
	if(CLACT_AnmActiveCheck( wk->act[wk->act_anim_id])){
		return 0;
	}
	return 1;
}


/**
 *	@brief	写真データメッセージ展開
 */
static void sub_PictMsgExpand(PICTURE_DATA* pic,WORDSET* wset,STRBUF* tmp,int heapID, SAVEDATA *save)
{
	//プレイヤー名展開
/**
	STRBUF_SetStringCode( tmp, (const STRCODE*)pic->name);
	WORDSET_RegisterWord( wset,0,tmp,PM_NEUTRAL,FALSE,PM_LANG);
*/
	WORDSET_RegisterPlayerName( wset, 0, SaveData_GetMyStatus(save) );

	//地名展開
	PNC_GetPlaceNameFromZoneID((const int)pic->zoneID,heapID,tmp);
	WORDSET_RegisterWord( wset,1,tmp,PM_NEUTRAL,FALSE,PM_LANG);

	//先頭ポケモンニックネーム展開
	STRBUF_SetStringCode( tmp, (const STRCODE*)pic->poke_name);
	WORDSET_RegisterWord( wset,2,tmp,PM_NEUTRAL,FALSE,PM_LANG);

	//日付展開
	WORDSET_RegisterNumber( wset, 3,
		GFDate_GetYear(pic->date) + 2000 , 4, NUMBER_DISPTYPE_ZERO, NUMBER_CODETYPE_HANKAKU );
	WORDSET_RegisterNumber( wset, 4,
		GFDate_GetMonth(pic->date) , 2, NUMBER_DISPTYPE_ZERO, NUMBER_CODETYPE_HANKAKU );
	WORDSET_RegisterNumber( wset, 5,
		GFDate_GetDay(pic->date) , 2, NUMBER_DISPTYPE_ZERO, NUMBER_CODETYPE_HANKAKU );
}

/**
 *	@brief	サムネール描画
 */
static void sub_ThumbnailWrite(FPV_WORK* wk)
{
	int i,j;

	for(i = 0;i < THUMB_BG_H;i++){
		for(j = 0;j < THUMB_BG_W;j++){
			GF_BGL_ScrFill( wk->bgl, DFRM_THUMB,
				(i*THUMB_BG_W+j)+1,THUMB_BG_PX+j ,THUMB_BG_PY+i, 1, 1, 0 );
		}
	}
	GF_BGL_LoadScreenV_Req( wk->bgl, DFRM_THUMB );
}

/**
 *	@brief	データ描画
 */
static void sub_PictDataDraw(FPV_WORK* wk)
{
	u32 siz;

	//やめるボタン描画
	siz = FontProc_GetPrintStrWidth( FONT_TOUCH, wk->msg.back, 0 );
	GF_STR_PrintColor( &wk->win[WIN_BACK], FONT_TOUCH, wk->msg.back,
		((BMP_BACK_SX*8)-siz)/2,0, MSG_NO_PUT,GF_PRINTCOLOR_MAKE(1,5,0), NULL );

	GF_BGL_BmpWinOnVReq(&wk->win[WIN_BACK]);

	//メッセージ展開
	sub_PictMsgExpand((PICTURE_DATA*)wk->pic_data.pic,wk->msg.wset,wk->msg.tmp,wk->heapID, wk->save);

	if( GetPicMonsNum(wk->pic_data.pic) > 1 ){
		WORDSET_ExpandStr( wk->msg.wset, wk->msg.tmp ,wk->msg.pic[1]);
	}else{
		WORDSET_ExpandStr( wk->msg.wset, wk->msg.tmp ,wk->msg.pic[0]);
	}

	GF_STR_PrintColor( &wk->win[WIN_PIC], FONT_SYSTEM, wk->msg.tmp,
		0,0, MSG_NO_PUT, FCOL_N_BLACK, NULL );

	GF_BGL_BmpWinOnVReq(&wk->win[WIN_PIC]);

	sub_ThumbnailWrite(wk);
}

//---------------------------------------------------------------------------
/**
 * @brief	6匹のポケモンのモンスターナンバーから、写真に写るポケモンの数を算出する
 *
 * @param	写真データポインタ
 */
//---------------------------------------------------------------------------
static u8 GetPicMonsNum(const PICTURE_DATA* pic)
{
	u8 num;
	u8 i;

	num = 0;
	for (i=0;i<PICTURE_POKE_MAX;i++){
		int mons_no = pic->poke[i].monsNo;
		if ( (0<mons_no)&&(mons_no<=MONSNO_END) ){
			num++;
		}
	}

	return num;
}

